import uuid
import json
from kafka import KafkaProducer, KafkaConsumer

KAFKA_HOST = "localhost"
KAFKA_PORT = 9092


kafka_producer = KafkaProducer(bootstrap_servers=KAFKA_HOST + ":" + str(KAFKA_PORT))

iam_login_1 = {
    "STATUS": "成功", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
    "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:19:37", "REMARK": "静态密码认证",
    "EVENT_NAME": "统一认证"
}

iam_login_2 = {
    "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
    "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:19:37", "REMARK": "静态密码认证",
    "EVENT_NAME": "统一认证"
}

iam_auth_1 = {
    "appName": "人力数字化", "appSn": "EHR", "name": "测试大明", "id": str(uuid.uuid4()), "sn": "dmtest",
    "user_name": "dmtest", "CREATE_TIME": "2024-03-26 17:19:37"
}

cas_1 = {
    "auth_type": "SDK_PASSWORD", "auth_result": "AUTH_SUCCESS", "auth_time": "2024-01-24 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
}

cas_2 = {
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-01-24 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
}

cas_3 = {
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_FAIL", "auth_time": "2024-01-24 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
}

cas_4 = {
    "auth_type": "SDK_PASSWORD", "auth_result": "AUTHORIZE_FAIL", "auth_time": "2024-01-24 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
}

# res = kafka_producer.send("cas", json.dumps(cas_1).encode("utf-8"))
# res2 = kafka_producer.send("iam_auth_logs", json.dumps(iam_auth_1).encode("utf-8"))
# print(res)

# consumer = KafkaConsumer("cas", bootstrap_servers=['localhost:9092'], auto_offset_reset='earliest',
#                          group_id="strategy")
# # res = kafka_producer.send("cas", json.dumps(cas_1).encode("utf-8"))
# msg = consumer.poll(timeout_ms=500)
# print(msg)

# for message in consumer:
#     # kafka_producer.send("cas", json.dumps(cas_1).encode("utf-8"))
#     # message value 和 offset 可通过 message.value 和 message.offset 访问
#     print(f"Message received: {message.value.decode('utf-8')}")

cas_res_1 = [
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:20:15.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:20:16.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
]

cas_res_2 = [
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_FAIL", "auth_time": "2024-04-26 15:20:13.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:21:15.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "AUTHORIZE_FAIL", "auth_time": "2024-04-26 15:23:20.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:23:20.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:23:21.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
{
    "auth_type": "SDK_PASSWORD", "auth_result": "VALIDATE_SUCCESS", "auth_time": "2024-04-26 15:25:23.829",
    "client_ip": "10.251.63.138", "url": "", "username": "zhaoteng", "auth_code": 1
},
]

iam_login_4 = [
    {
        "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 01:19:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
    {
        "STATUS": "成功", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 04:18:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
    {
        "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:19:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
    {
        "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:20:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
    {
        "STATUS": "成功", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:21:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
    {
        "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:22:37", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
     {
        "STATUS": "失败", "CLIENT_INFO": "系统:Windows 10", "IP": "10.10.10.10", "ID": str(uuid.uuid4()),
        "USER_NAME": "测试小明", "CREATE_TIME": "2024-03-26 17:22:47", "REMARK": "静态密码认证",
        "EVENT_NAME": "统一认证"
    },
]

iam_auth_4 = [
    {
        "appName": "人力数字化", "appSn": "EHR", "name": "测试大明", "id": str(uuid.uuid4()), "sn": "dmtest",
        "user_name": "dmtest", "CREATE_TIME": "2024-04-30 12:19:37"
    },
    # {
    #     "appName": "人力数字化", "appSn": "EHR", "name": "测试大明", "id": str(uuid.uuid4()), "sn": "dmtest",
    #     "user_name": "dmtest", "CREATE_TIME": "2024-04-30 17:19:37"
    # }
]
